<?php

namespace App\Models\OpenShop\SiteLocation;

use App\Models\BaseModel;
use App\Models\Common\OperateLogModel;
use App\Models\Shop\ShopModel;
use App\Models\Traits\KfSoftDeletes;
use App\Models\Traits\KfUid;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;

class IntendedSiteSelectionModel extends BaseModel
{
    use HasFactory, KfSoftDeletes, KfUid;

    protected $fillable = [
        'shopId',
        'poiName',
        'poiAddress',
        'provinceCode',
        'cityCode',
        'districtCode',
        'addressPrefix',
        'longitude',
        'latitude',
        'siteSelectionImg',
        'createdAt',
        'createdByUid',
        'updatedAt',
        'updatedByUid',
        'isDeleted',
        'wgNumber',
        'type',
        'status',
        'followUpUserId'
    ];

    protected $table = "open_shop_intended_site_selection";

    /**
     * @return HasOne
     */
    public function shopRel(): HasOne
    {
        return $this->hasOne(ShopModel::class, "id", "shopId");
    }

    public function records(): HasMany
    {
        return $this->hasMany(OperateLogModel::class, 'businessId', 'id')->where('business', OperateLogModel::BUSINESS_INTENDED_SITE_LOCATION)->orderByDesc('id');
    }
}
